/*
Light Javascript Framework
Name Space: LF
verson: 0.2

Developed by Glools Team at 2010-10-26
*/

(function (){
    try{
        if (LF || window.LF) {
            alert("System error, base Namespace have been registered.");
            return true;
        }
    }catch(e){
        alert(e.message);
        return true;
    }

    var LF = {
        /*
            Global variables
            - 
        */
        'ns' : {
            '_vars' : {},
            '_plugins' : {},
            '_apps' : {},
            '_utilites' : {}
        },
        
        'getNameSpace' : function(n) {
            return LF.ns['_'+n];
        },
        
        'appNameSpace' : function(n, v) {
            return LF._nameSpace(n, 'apps', v);
        },
        
        'pluginNameSpace' : function(n, v) {
            return LF._nameSpace(n, 'plugins', v);
        },
        
        'utiNameSpace' : function(n,v) {
            if ('object'!=typeof(v)) {
                return false;
            }
            LF._nameSpace(n, 'utilites', v);
        },
        
        'varsNameSpace' : function(n,v) {
            if ('string' != typeof(n)) {
                return 'undefined';
            }
            
            return LF._nameSpace(n, 'vars', v);
        },
        
        '_nameSpace' : function(n, p, v) {
            if ('string' != typeof(n)) {
                return false;
            }
            p = '_'+p;
            
            if (!LF.ns[p]) {
                alert('[Error by LF] Base name \"'+p+'\" does not allowed.');
                return false;
            }
            
            LF.ns[p][n] = v;
            return LF.ns[p][n];
        }
    }
    window.LF = LF;
})();


/*
    Load and run registered plugins after document loaded.

    note: hooks
    main: the method will be executed in plugin.
*/

jQuery(document).ready(function(){
    
    var plugins = LF.getNameSpace('plugins');
    
    
    for(var p in plugins) {
    
        var plugin = plugins[p];
        
        switch(typeof(plugin)) {
            case 'object':
                if(plugin.main && 'function' == typeof(plugin.main)){
                    plugin.main.apply(plugin);
                }
                
                break;

            case 'function':
                plugin.apply(plugin);
                break;
            default:
                alert(p+' is type '+typeof(plugin));
        }
        
    }
});
